package com.baselibrary.libs.View.kalaokText;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;

import com.baselibrary.libs.Utils.log.LogUtils;

/**
 * Created by 35876 于萌萌
 * 创建日期: 18:08 . 2017年01月25日
 * 描述:带 卡拉OK 效果的TextView
 * <p>
 * <p>
 * 备注:
 */

public class TextView_kalaok_Plus extends TextView {

    private Paint mPaintBg;
    private Paint mPaint;
    private int mWith;
    private boolean mBoolean;
    private String mText_onDraw;

    public TextView_kalaok_Plus(Context context) {
        super(context);
        initPaint(context);
    }



    public TextView_kalaok_Plus(Context context, AttributeSet attrs) {
        super(context, attrs);
        initPaint(context);
    }

    public TextView_kalaok_Plus(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPaint(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        LogUtils.i("我是onDraw 里面赋值的内容是"+mText_onDraw);
        canvas.drawText(mText_onDraw,20,30,mPaintBg);


        canvas.clipRect(new Rect(mWith,0,mWith+200,80));
        if (mBoolean){

            canvas.drawText(mText_onDraw,20,30,mPaint);
        }
    }

    public void setWith(int i,boolean b){
        mBoolean = b;
        mWith = i*2;
        invalidate();
    }
    public void setText_onDraw(String text_onDraw){
        mText_onDraw = text_onDraw;
        invalidate();
    }

    private void initPaint(Context context) {
        //底色
        mPaintBg = new Paint();
        mPaintBg.setTextSize(30);
        mPaintBg.setAntiAlias(true);
        mPaintBg.setColor(Color.BLACK);

        mPaint = new Paint();
        mPaint.setTextSize(30);
        mPaint.setAntiAlias(true);
        mPaint.setColor(Color.RED);


    }
}
